package com.shujia.spark.mllib

import org.apache.spark.mllib.classification.LogisticRegressionModel
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.mllib.regression.LabeledPoint
import org.apache.spark.mllib.util.MLUtils
import org.apache.spark.rdd.RDD

object Demo4LoadModel {

  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setMaster("local").setAppName("app")

    val sc = new SparkContext(conf)

    //加载数据
    var rdd: RDD[LabeledPoint] = MLUtils.loadLibSVMFile(sc, "spark/data/人体指标.txt")


    //取出一条数据
    val data = rdd.take(1)(0)


    //加载本地的模型
    val model = LogisticRegressionModel.load(sc, "spark/data/model")

    //使用模型预测
    val label = model.predict(data.features)

    println(data.label + "\t" + label)


  }

}
